var $,layer,form,table,laydate,upload;
layui.use(['jquery','layer','form','table','laydate','upload'],function(){
    $ = layui.$,layer = layui.layer,form = layui.form,table = layui.table,laydate = layui.laydate,upload = layui.upload;
    form.on('submit(sub)',function(data){
        var user = data.field;
        console.log(user);
        var qian = {
            'avatarUrl': user.avatarUrl
            ,'consumption': user.consumption
            ,'email': user.email
            ,'fullName': user.fullName
            ,'idCard': user.idCard
            ,'nickname': user.nickname
            ,'phone': user.phone
            ,'studyDate': user.studyDate
            ,'userCode': user.userCode
            ,'sex': user.sex
            ,'status': user.status
            ,'userId': userId
        }
        console.log(qian);
        var jinsi = {
            'integration': user.integration
            ,'profession': user.profession
            ,'studyContent': user.studyContent
            ,'type': user.type
            ,'userId': userId
        }
        console.log(jinsi);


        $.ajax({
            url: '/user/editJinsiUser'
            ,data: qian
            ,dataType: 'json'
            ,success:function(data){
                $.ajax({
                    url: '/user/editJinsiUserJ'
                    ,data: jinsi
                    ,dataType: 'json'
                    ,success:function(data){
                        var layer = parent.layer;
                        layer.close(layer.index);
                        layer.msg('修改成功');
                    }
                });
            }
        });



    });
});

var userId = parent.$('#userId').val();

$.ajax({
    url: '/user/getJinsiUsers'
    ,data: {'userId': userId}
    ,dataType: 'json'
    ,success:function(data){
        var user = data.data[0];
        console.log(user);
        $('input[name=nickname]').val(user.nickname);
        $('input[name=userCode]').val(user.userCode);
        $('input[name=fullName]').val(user.fullName);
        $('input[name=profession]').val(user.profession);
        $('input[name=studyDate]').val(user.studyDate);
        $('input[name=integration]').val(user.integration);
        $('input[name=consumption]').val(user.consumption);
        $('input[name=entranceDate]').val(user.entranceDate);
        $('input[name=graduationDate]').val(user.graduationDate);
        $('input[name=createDate]').val(user.createDate);
        $('input[name=idCard]').val(user.idCard);
        $('input[name=phone]').val(user.phone);
        $('input[name=email]').val(user.email);
        $('textarea[name=studyContent]').val(user.studyContent);
        $('#avatarUrl').attr('src',user.avatarUrl);
        $('input[name=avatarUrl]').val(user.avatarUrl);
        $('input[name=type]').val(user.type);
        if(user.type == 2){
            $('input[name=typeType]').val('未毕业');
        }else if(user.type == 3){
            $('input[name=typeType]').val('已毕业');
        }else{
            $('input[name=typeType]').val('数据错误');
        }
        $('input[name=status]').val(user.status);
        if(user.status == 2){
            $('input[name=statusStatus]').val('正常');
        }else if(user.status == 3){
            $('input[name=statusStatus]').val('禁言');
        }else if(user.status == 4){
            $('input[name=statusStatus]').val('注销');
        }else if(user.status == 5){
            $('input[name=statusStatus]').val('封停');
        }
        if(user.sex == 1){
            $('input[name=sex][value="1"]').attr('checked',true);
        }else if(user.sex == 2){
            $('input[name=sex][value="2"]').attr('checked',true);
        }
        form.render();
    }
});
//修改头像
var uploadInst = upload.render({
    elem: '#avatarUrl'
    ,auto: true
    ,url: '/Upload/uploadImages'
    ,field: 'file'
    ,choose:function(obj){
        var files = obj.pushFile();
        obj.preview(function(index,file,result){
            $('#avatarUrl').attr('src',result);
        })
    }
    ,done:function (res) {
        $('input[name=avatarUrl]').val(res.data);
    }
});
//取消
cancel = function cancel(){
    var layer = parent.layer;
    layer.close(layer.index);
}